Fix cross-compilation of native modules in Dockerfile#66
Merged
djannot merged 1 commit intokagent-dev:mainfrom Mar 9, 2026
Merged
Fix cross-compilation of native modules in Dockerfile#66djannot merged 1 commit intokagent-dev:mainfrom
djannot merged 1 commit intokagent-dev:mainfrom
Conversation
Change builder stage from $BUILDPLATFORM to $TARGETPLATFORM so that native Node.js modules (better-sqlite3) are compiled for the target architecture rather than the build machine's architecture. With $BUILDPLATFORM, cross-compilation scenarios (e.g., arm64 Mac building for amd64 clusters) produce native binaries for the wrong architecture, causing runtime failures. Fixes kagent-dev#65 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
b3b326f to
8c27ff1
Compare
djannot
approved these changes
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$BUILDPLATFORMto$TARGETPLATFORMso that native Node.js modules (better-sqlite3) are compiled for the target architectureProblem
When building on arm64 (e.g., Apple Silicon) targeting amd64,
$BUILDPLATFORMcausesnode-gypto compile thebetter-sqlite3C extension for arm64. The resulting binary fails at runtime on amd64 nodes withexec format erroror shared object errors.Fix
One-line change:
FROM --platform=$TARGETPLATFORMinstead ofFROM --platform=$BUILDPLATFORMin the builder stage. This ensures native modules match the target architecture. The tradeoff is slower cross-arch builds (QEMU emulation) but correct binaries.Fixes #65
🤖 Generated with Claude Code